package guda.house.dal.dao.impl;

import guda.grape.autogen.common.BaseDAO;
import guda.house.dal.dao.RoleDAO;
import guda.house.dal.dataobject.RoleDO;
import guda.grape.autogen.common.page.BaseQuery;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RoleDAOImpl extends BaseDAO implements RoleDAO {

    @Override
	public Long insert(RoleDO role) {
	      try {
                return (Long) getSqlMapperW().insert("role.insert",role);
          } catch (Exception e) {
                throw new RuntimeException(e);
          }

	}

    @Override
	public RoleDO getRoleById(Long roleId) {
	    return (RoleDO)getSqlMapClientTemplate().queryForObject("role.getRoleById", roleId);
	}

    @Override
	public boolean delRoleById(Long roleId) {
	    int num = 0;
        try {
            num = getSqlMapperW().delete("role.delRoleById",roleId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if(num>0){
            return true;
        }else{
            return false;
        }
	}

    @Override
	public List<RoleDO> getRoleByIds(List idsList) {
        Map m = new HashMap();
        m.put("idsList",idsList);
		return getSqlMapClientTemplate().queryForList("role.selectByIds", m);
	}

    @Override
	public void cleanAutoIncrement(Long roleId) {
	    try {
            getSqlMapperW().update("role.cleanAutoIncrement",roleId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
	}

    @Override
    public List<RoleDO> selectForPage(BaseQuery baseQuery) {
        return getSqlMapClientTemplate().queryForList("role.selectForPage", baseQuery);
    }

    @Override
    public int countForPage(BaseQuery baseQuery) {
        return (Integer)getSqlMapClientTemplate().queryForObject("role.countForPage",baseQuery);
    }

    @Override
    public void updateByIdSelective(RoleDO role) {
        try {
            getSqlMapperW().update("role.updateByIdSelective",role);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}

